package com.gitee.wsl.prop

import com.gitee.wsl.reflect.TypeInfo
import com.gitee.wsl.reflect.typeInfo
import kotlin.jvm.JvmOverloads
import kotlin.jvm.JvmSynthetic

/**
 * Specifies a key for an attribute in [Attributes]
 * @param T is a type of the value stored in the attribute
 * @param name is a name of the attribute for diagnostic purposes. Can't be blank
 */
@JvmSynthetic
 inline fun <reified T> AttributeKey(name: String): AttributeKey<T> = AttributeKey(name, typeInfo<T>())

/**
 * Specifies a key for an attribute in [Attributes]
 * @param T is a type of the value stored in the attribute
 * @property name is a name of the attribute for diagnostic purposes. Can't be blank
 * @property type the recorded kotlin type of T
 */
 data class AttributeKey<T> @JvmOverloads constructor(
    val name: String,
    val type: TypeInfo = typeInfo<Any>(),
) {
    init {
        require(name.isNotBlank()) { "Name can't be blank" }
    }

    override fun toString(): String = "AttributeKey: $name"

    companion object{
        fun int(name: String) = AttributeKey<Int>(name)
    }
}